<?php

/**
 * This is the model class for table "pemohon".
 *
 * The followings are the available columns in table 'pemohon':
 * @property integer $no_pmh
 * @property integer $no_reg
 * @property string $tahun
 * @property string $nama_pmh
 * @property string $alamat_pmh
 * @property string $tgl_pmh
 * @property string $noreg_njop
 * @property string $npwp
 * @property string $kode_user
 *
 * The followings are the available model relations:
 * @property Users $kodeUser
 * @property DokTerima $noReg
 */
class Pemohon extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'pemohon';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('tgl_pmh, kode_user', 'required'),
			array('no_pmh, no_reg', 'numerical', 'integerOnly'=>true),
			array('tahun', 'length', 'max'=>4),
			array('nama_pmh', 'length', 'max'=>35),
			array('alamat_pmh', 'length', 'max'=>75),
			array('noreg_njop', 'length', 'max'=>50),
			array('npwp', 'length', 'max'=>15),
			array('kode_user', 'length', 'max'=>8),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('no_pmh, no_reg, tahun, nama_pmh, alamat_pmh, tgl_pmh, noreg_njop, npwp, kode_user', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'kodeUser' => array(self::BELONGS_TO, 'Users', 'kode_user'),
			'noReg' => array(self::BELONGS_TO, 'DokTerima', 'no_reg'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'no_pmh' => 'No Pmh',
			'no_reg' => 'No Reg',
			'tahun' => 'Tahun',
			'nama_pmh' => 'Nama Pmh',
			'alamat_pmh' => 'Alamat Pmh',
			'tgl_pmh' => 'Tgl Pmh',
			'noreg_njop' => 'Noreg Njop',
			'npwp' => 'Npwp',
			'kode_user' => 'Kode User',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('no_pmh',$this->no_pmh);
		$criteria->compare('no_reg',$this->no_reg);
		$criteria->compare('tahun',$this->tahun,true);
		$criteria->compare('nama_pmh',$this->nama_pmh,true);
		$criteria->compare('alamat_pmh',$this->alamat_pmh,true);
		$criteria->compare('tgl_pmh',$this->tgl_pmh,true);
		$criteria->compare('noreg_njop',$this->noreg_njop,true);
		$criteria->compare('npwp',$this->npwp,true);
		$criteria->compare('kode_user',$this->kode_user,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Pemohon the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
